/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * Auto7.1
 */

package com.register.Model;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;

/**
 *
 * @author Yogesh
 */
public class Step1_Model extends org.apache.struts.action.ActionForm {
    
    String firstName;

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public String getEmailId() {
        return emailId;
    }

    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
  String lastName;
  String emailId;
  String password;
  String confirmPassword;

  String mobileNumber;

    public String getMobileNumber() {
        return mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    String domain;

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    String pic="VehicleHai/pic.vhi";

    public String getPic() {
        return pic;
    }

    String activationCode="";

    public String getActivationCode() {
        return activationCode;
    }

    public void setActivationCode(String activationCode) {
        this.activationCode = activationCode;
    }

    String iframe="";

    public String getIframe() {
        return iframe;
    }

    public void setIframe(String iframe) {
        this.iframe = iframe;
    }


    String ipAddress;

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    String flag="0";

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    /**
     *
     */
    public Step1_Model() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();

        //        if (getName() == null || getName().length() < 1) {
//            errors.add("name", new ActionMessage("error.name.required"));
//            // TODO: add 'error.name.required' key to your resources
//        }


        //-------------------------------------------------------------------------------------------------------------------//



                 org.hibernate.SessionFactory sessionFactory=com.Auto.Common.Userinformtion.Hibernate.Userinformation_HibernateUtil.getSessionFactory();
                 org.hibernate.Session Opensession=sessionFactory.openSession();
                 org.hibernate.Transaction transaction=Opensession.beginTransaction();


                  org.hibernate.Query query=Opensession.createQuery("from com.Auto.Common.Userinformtion.Hibernate.Userinformation where emailId='"+emailId+"' and password='"+password+"'");


                         java.util.List l=query.list();

                            if(l.isEmpty()){

                                flag="1";                               

                            }
                            else{

                              for(Object o:l){

                      com.Auto.Common.Userinformtion.Hibernate.Userinformation uifor=(com.Auto.Common.Userinformtion.Hibernate.Userinformation)o;

                              firstName=uifor.getFirstName();
                              lastName=uifor.getLastName();

                              }
                                
                                flag="0";
                            }



                         if(flag.equals("1")){

                               query=Opensession.createQuery("from com.Auto.Common.Userinformtion.Hibernate.Userinformation where emailId='"+emailId+"'");
                               l=query.list();

                                 if(l.isEmpty()){

                                     }
                                 else{
                                        errors.add("errors.emailTacken", new ActionMessage("errors.emailTacken"));
                                        flag="0";
                                 }

                         }


                        

                      // errors.add("errors.emailTacken", new ActionMessage("errors.emailTacken"));
                               
                       

                               

                         







                         




 if(flag.equals("1")){


        if(emailId.contains("gmail.com")){
            domain ="<a  href=\"JavaScript:newPopup('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&hl=en&emr=1&elo=1');\"><button  class=\"blue\"><img src='https://ssl.gstatic.com/accounts/ui/logo_2x.png'/><br>Click Hear To Open Your gmail</button></a>";
        }

        if(emailId.contains("yahoo.com")){

            domain ="<a  href=\"JavaScript:newPopup('https://login.yahoo.com/config/mail?&.src=ym&.intl=in');\"><button  class=\"blue\"><img src='https://s1.yimg.com/rz/d/yahoo_en-US_f_p_bestfit.png'/><br>Click Hear To Open Your Yahoo</button></a>";
        }
        if(emailId.contains("rediff.com")){

             domain ="<a  href=\"JavaScript:newPopup('http://www.rediff.com/');\"><button  class=\"blue\"><img src='http://upload.wikimedia.org/wikipedia/en/4/4a/Rediffmail_NG-logo.png'/><br><br>Click Hear To Open Your Rediff</button></a>";
        }

         if(emailId.contains("hotmail.com")){

             domain ="<a  href=\"JavaScript:newPopup('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=12&ct=1401735186&rver=6.4.6456.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us&cbcxt=mai&snsc=1');\"><button  class=\"blue\"><img src='https://sc.imp.live.com/content/dam/imp/surfaces/mail_signin/header/logo_mail.png'/><br><br>Click Hear To Open Your Hotmail</button></a>";
        }

        String str="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                StringBuffer sb = new StringBuffer(10);

             for (int i=0;  i<10;  i++) {


                 int ndx = (int)(Math.random()*str.length());

                 sb.append(str.charAt(ndx));

             }

             activationCode=sb+"";

            


              InetAddress ip;
	try {

		ip = InetAddress.getLocalHost();
		ipAddress=ip.getHostAddress();



	} catch (UnknownHostException e) {

		e.printStackTrace();

	} 



              if(mobileNumber.substring(0,2).equals("91")&&mobileNumber.length()==12){
                  mobileNumber=mobileNumber.substring(2);

              }

             String link="http://api.msandesh.in/desk2web/SendSMS.aspx?UserName=motivate&password=field9949&MobileNo=91"+mobileNumber+"&SenderID=yogesh&CDMAHeader=+91"+"8550900381"+"&Message=Thank You "+firstName+" "+lastName+"   For Registering On www.VehicleHai.com .\nYour Activation Code Is : "+activationCode+"  Registration Done By Ip Address:"+ipAddress+"&isFlash=false";

                 iframe="<iframe src=\""+link+"\" width='0.5' height='0.5' hidden=\"\"/>";



//             try {
//            Thread.sleep(12000);
//        } catch (Exception e) {
//        }


 }//End Of If Flag=1
 


        return errors;
    }
}
